package cn.edu.kzjsxy.graduationproject.controller;

import cn.edu.kzjsxy.graduationproject.common.Result;
import cn.edu.kzjsxy.graduationproject.tool.AliOSSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author：chén jiā jùn
 * @Create：2024年04月25日16:56
 * 测试文件上传
 */
@Api(tags = "测试文件上传")
@RestController
@RequestMapping("/fileUpload")
public class FileUpload {

	@Autowired
	private AliOSSUtils aliOSSUtils;
	@PostMapping("/123")
	@ApiOperation("测试文件上传")
	public Result test(MultipartFile file ) throws IOException {
		String url = aliOSSUtils.upload(file);
		return  Result.success(url);
	}


	@PostMapping("/12313213")
	@ApiOperation("测试文件上传2")
	public Result test(String name,MultipartFile file ) throws IOException {
		String url = aliOSSUtils.deleteAndSaveNewFile(name,file);
		System.err.println("文件名是："+url);
		return  Result.success(url);
	}

}
